package com.czk.stream;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Stream;

import org.junit.Test;

public class StreamDemo {
	@Test
	public  void fun_1() {
		List<String> list=new ArrayList<String>();
		list.add("陈彰坤");
		list.add("陈章杰");
		list.add("宁中琼");
		list.add("陈彦瀚");
		list.add("陈坤");
		//使用jdk8新特性，stream方式进行遍历，并且筛选
		//同时满足两种条件
		list.stream().filter(name->name.endsWith("坤")).filter(name->name.length()==2)
		.forEach(System.out::println);
	}
	//获取stream流的方式
	@Test
	public void getStream_1() {
		//将集合转换为stream流
		List<String> list=new ArrayList<String>();
		Stream<String> stream = list.stream();
		//set
		Set<String> set=new HashSet<String>();
		Stream<String> stream2 = set.stream();
		//map
		Map<String, String> map=new HashMap<String, String>();
		//获取键
		Set<String> keySet = map.keySet();
		Stream<String> stream3 = keySet.stream();
		//获取值
		Collection<String> values = map.values();
		Stream<String> stream4 = values.stream();
		
		//获取键值对
		Set<Entry<String,String>> entrySet = map.entrySet();
		Stream<Entry<String, String>> stream5 = entrySet.stream();
		
		//数组转换为流
		Stream<Integer> of = Stream.of(1,2,3,4);
		//可变参数可以传递数组
		int[] arr= {1,2,3,4,5};
		Stream<int[]> of2 = Stream.of(arr);
		of2.forEach(i->{System.out.println(i);});
	}
}
